//
//  __config.swift
//  soapp_Example
//
//  Created by zhuxietong on 2019/4/26.
//  Copyright © 2019 CocoaPods. All rights reserved.
//

import Foundation
import soapp
import JoLoading
//import Toast
import MBProgressHUD
import Eelay
import Kingfisher
import WebKit

let __demo_url = "http://firstvar.com/famous-json/figure"
let __demo_handle:JoTaskHandle = {
    result,url,mode in
    //    http://firstvar.com/famous-json/figure
    
    
    switch (mode ?? .normal){
    case .apijson(let apijson):
        let jsonmode = ApijsonTask(request: apijson, response: result)
        
        return jsonmode.handle
    default:
        if let dict = result as? NSDictionary{
            let mu_dict = dict.mutable_dictionary
            
            if mu_dict["state",""] == "1"
            {
                let data = mu_dict["data"]
                return (true,mu_dict["message",""],data as RootData)
            }
            if mu_dict["state",""] == "3"
            {
                JoUser.loginUser()?.loginOut()
                return (false,"用户token已失效",NSMutableDictionary())
            }
            if mu_dict["state",""] == "0"
            {
                let msg = mu_dict["message",""]
                if msg.contains("token wrong"){
                    JoUser.loginUser()?.loginOut()
                }
                let data = mu_dict["data"]
                return (false,mu_dict["message",""],data as RootData)
            }
        }
        return (false,"",NSMutableDictionary())
    }
}



extension __app{
    
}


class __config {
    static var isTest = false
    static func build(){
        
     
        
        LoadingPresenterDefautLoadingClass = FlatLoading.self
//        URLOwner.thisAppScheme = "danceunionn"
        
        
        //        URLOwner.openSelfTask = {
        //            path,url in
        //            print("DDD=====|\(path)==|==|\(url)")
        //        }
        //        __SCconfig.
        
        
        let jsObserver:(WKScriptMessage,UIViewController?) -> Bool = {
            msg,ctr in
            if let one = msg.body as? Dictionary<String, AnyObject>
            {
                let link = one.mutable_dictionary["link",""]
                AppLink.open(link: link, at: ctr, present: nil)
            }
            return true
        }
        
        WebController.JSObservers = [jsObserver]
        JoTask.defaultHandle = {
            result,url,mode in
            switch (mode ?? .normal){
            case .apijson(let apijson):
                let jsonmode = ApijsonTask(request: apijson, response: result)
                return jsonmode.handle
            default:
                if let dict = result as? NSDictionary{
                    let mu_dict = dict.mutable_dictionary
                    
                    if mu_dict["status",""] == "1"
                    {
                        let time = mu_dict["time",""]
                        
                        if time.jolength >= 10
                        {
                            FK.remoteTimeStamp = time
                        }
                        let data = mu_dict["data"]
                        return (true,mu_dict["message",""],data as RootData)
                    }
                    if mu_dict["status",""] == "3"
                    {
                        JoUser.loginUser()?.loginOut()
                        let data = mu_dict["data"]
                        return (false,"登录已失效",data as RootData)
                    }
                    if mu_dict["status",""] == "0"
                    {
                        //                        let msg = mu_dict["message",""]
                        //                        if msg.contains("token wrong"){
                        //                            JoUser.loginUser()?.loginOut()
                        //                        }
                        let data = mu_dict["data"]
                        return (false,mu_dict["message",""],data as RootData)
                    }
                }
                return (false,"",NSMutableDictionary())
            }
        }
        
       
        //        JoUser.unBindPushTokenBlock = {
        //            SoNum.clear()
        //
        //            CloudPushSDK.unbindAccount { (result) in
        //                if let r = result{
        //                    if r.success{
        //                        debugPrint("unbind CloudPushSDK success")
        //                    }
        //                    else{
        //                        debugPrint("unbind CloudPushSDK error :\(String(describing: r.error))")
        //                    }
        //                }
        //            }
        //        }
        //
        
        
        
        
        //        AppLink.routers.append(MallLink.self)
        //        AppLink.routers.append(IweLink.self)
        //        AppLink.routers.append(MessageType.self)
        
        
        
        //        EeMsgType.appendObserver(types: AppMsgType.types)//添加红的标记类型
        
        Date.stamp精度 = .秒//设置项目时间戳精确度
        UIViewController.__swizzing()
//        EeNavigationController.open_nav_swizzle()
        EeTopStyle.mode = .rtnav
        EeTopStyle.default = __theme.default() //设置默认的top_style  与NavigationBar,statusBar 样式有关
        EeTopStyle.white = __theme.white()
        EeTopStyle.blur_light = __theme.blur()
        
        
        //全局设置每个 http 头部的参数，本项目中的http 是token头部授权
        //        JoTask.headerCreator = {
        //            let headers = [String:String]()
        //            return headers
        //        }
        //
        JoTask.headerCreator = {
            var ps = [String:String]()
            if let token = JoUser.loginUser()?.token
            {
                ps["token"] = token
                
            }
            ps["lat"] = "\(EeLocator.Setting.current_lat)"
            ps["lng"] = "\(EeLocator.Setting.current_lng)"
            ps["device-type"] = "iOS"
            ps["device-id"] = __app.device_id
            ps["x-timestamp"] = Date()["STAMP"]
            ps["client-version"] = __app.client_version
            ps["system-version"] = __app.system_verion
            
            return ps
        }
        
        
        JoTask.debugLog = true//开启全局JoTask 网络试调打印
        WebController.tinyColor = UIColor(shex:__main_hex) //设置WebController 价值进度条的颜色
        
        
        PageConfig.page_key = "page"
        PageConfig.page_size_key = "num"
        PageConfig.page_begin = 1
        PageConfig.is_index_page_key = false
        //        PageConfig.dataStatusJudge = __dataStatusJudge
        
        LoadingPresenterDefautLoadingClass = FlatLoading.self//全局设置LoadingPresenter 加载控件
        
        //        let v = UIView()
        //        v.makeToast("100", duration: 0.4, position: .center, title: "sss", image: nil, style: ToastStyle()) { (finish) in
        //
        //        }
        
//        String.showTextMethod = {
//            if let r_window = UIApplication.shared.delegate?.window
//            {
//
//                var style = ToastStyle()
//                style.cornerRadius = 1.0
//                style.backgroundColor = UIColor.white
//                style.messageFont = UIFont.systemFont(ofSize: 14)
//                style.messageColor = UIColor(shex:"#222")
//                style.shadowColor = UIColor(shex:"#000")
//                style.shadowOpacity = 0.6
//                style.shadowOffset = [0,0]
//                style.shadowRadius = 10
//                style.displayShadow = true
//
//                r_window?.makeToast("\($0)", duration: ToastManager.shared.duration, position: .center, title: nil, image: nil, style: style) { (finish) in
//
//                }
//                //                r_window?.makeToast("\($0)")
//            }
//        }
        
        __images =
            [
                "http://img.aoji.cn/2015/0205/fQTqAmzFH0qm.JPG",
                "http://g.hiphotos.baidu.com/image/pic/item/9e3df8dcd100baa14b2c47714e10b912c9fc2ef3.jpg",
                "http://img.taopic.com/uploads/allimg/140218/235092-14021Q0045581.jpg",
                "http://pic.90sjimg.com/back_pic/qk/back_origin_pic/00/03/43/982b8445024ebf67cc90583232eb94b9.jpg",
                "http://pic.90sjimg.com/back_pic/qk/back_origin_pic/00/03/93/860c19c189ec9ab136ed8d6662b6da96.jpg",
                "http://b.hiphotos.baidu.com/image/pic/item/35a85edf8db1cb13d8090cd2d454564e93584b8a.jpg",
                "http://h.hiphotos.baidu.com/image/pic/item/a686c9177f3e67098632153e32c79f3df9dc55c4.jpg",
                "http://img.pconline.com.cn/images/upload/upc/tx/photoblog/1409/02/c0/38147679_38147679_1409604133114.jpg",
                "http://imgsrc.baidu.com/imgad/pic/item/8694a4c27d1ed21be8d4f9dca66eddc451da3fee.jpg",
                "http://cyjctrip.qiniudn.com/12875/1352218279332p17bb7q3g315d41vma132t1jn41r8i8.jpg",
                "http://img.pconline.com.cn/images/upload/upc/tx/photoblog/1409/02/c0/38147679_38147679_1409604147864.jpg",
                "http://c.hiphotos.baidu.com/image/pic/item/77094b36acaf2edd991b4823841001e938019315.jpg",
                "http://h.hiphotos.baidu.com/image/pic/item/29381f30e924b89976cb78f267061d950b7bf601.jpg",
                "http://a.hiphotos.baidu.com/image/pic/item/30adcbef76094b36d4bfddfea9cc7cd98d109df0.jpg",
        ]
        
        CoHud._loading = { view in
            if let a_view = view{
                
                var hud:MBProgressHUD? = MBProgressHUD(view: a_view)
                if hud == nil{
                    hud = MBProgressHUD.showAdded(to: a_view, animated: true)
                }
                
                hud?.backgroundView.style = .solidColor
                hud?.backgroundView.color = UIColor(shex: "#0003")
                a_view.isUserInteractionEnabled = false
            }
        }
        
        CoHud._dismiss = { view in
            if let a_view = view{
                MBProgressHUD.hide(for: a_view, animated: true)
                a_view.isUserInteractionEnabled = true
            }
        }
        
    }
    
}

var __logos = [
    "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3547592982,1978197711&fm=200&gp=0.jpg",
    "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1443299318,121744606&fm=27&gp=0.jpg",
    "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1017980852,3420383746&fm=27&gp=0.jpg",
    "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1252256153,3419487072&fm=27&gp=0.jpg",
    "https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1895838255,3248645471&fm=27&gp=0.jpg",
    "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=871295046,2601159057&fm=27&gp=0.jpg",
    "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3255919467,4117243677&fm=27&gp=0.jpg"
]

var __goods = [
    "http://imgsrc.baidu.com/image/c0%3Dpixel_huitu%2C0%2C0%2C294%2C40/sign=492a5f260c0828387c00d454d1e1cc6d/42166d224f4a20a42876c8fe9b529822720ed09b.jpg",
    "http://img008.hc360.cn/m2/M02/5B/8E/wKhQcVQ7dCOEeWVwAAAAAC57UX8062.jpg",
    "http://a.vpimg4.com/upload/merchandise/pdc/921/179/8390563877277179921/0/6921552600606-110_1.jpg",
    "http://img14.360buyimg.com/n12/jfs/t298/184/444026135/484797/3366743/54116596Nf1de7844.jpg",
    "http://imgsrc.baidu.com/image/c0%3Dshijue1%2C0%2C0%2C294%2C40/sign=b248fb145382b2b7b392318759c4a19a/d1a20cf431adcbef65051d16a6af2edda3cc9fe8.jpg",
    "http://img009.hc360.cn/g8/M02/09/41/wKhQt1O6FM2EBELmAAAAAKDGvRI169.jpg",
    "http://imgsrc.baidu.com/image/c0%3Dshijue1%2C0%2C0%2C294%2C40/sign=8b0f0137454a20a425133484f83bf257/472309f790529822ba1760e6ddca7bcb0a46d4eb.jpg",
    "http://img12.360buyimg.com/imgzone/jfs/t1150/67/1491868118/427177/3fd84657/572d9c3cN7ca185c3.jpg",
]

var __goodsNames = [
    "帅帅的高跟鞋",
    "白领正装",
    "秋末围巾（商务款）",
    "阿迪达斯新款运动鞋",
    "夏日泳装情侣款",
    "冬款妈妈装",
    "中学青春系列",
]
var __seller = [
    "品牌名称1",
    "品牌名称2",
    "品牌名称3",
    "品牌名称4",
    "品牌名称5",
    "品牌名称6",
    "品牌名称7"
]
